﻿<%@ Page Title="Complete Purchase" Language="C#" MasterPageFile="~/MainSite.master" AutoEventWireup="true" CodeFile="CompletePurchase.aspx.cs" Inherits="CompletePurchase" %>
<%@ MasterType VirtualPath="~/MainSite.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MWSContentPlaceHolder1" Runat="Server">

<div class="RedPageBody">


<table cellpadding="50px">
<tr>
    <td>
        <asp:GridView ID="CustomerInfoGridView" runat="server" 
            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="CID" 
            DataSourceID="CustInfoDataSource" ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="CID" HeaderText="CID" ReadOnly="True" 
                    ItemStyle-CssClass="invisible" HeaderStyle-CssClass="invisible" >
                <HeaderStyle CssClass="invisible"></HeaderStyle>
                <ItemStyle CssClass="invisible"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="FNAME" HeaderText="First Name" SortExpression="FNAME" />
                <asp:BoundField DataField="LNAME" HeaderText="Last Name" SortExpression="LNAME" />
                <asp:BoundField DataField="ADDR" HeaderText="Address" SortExpression="ADDR" />
                <asp:BoundField DataField="CITY" HeaderText="City" SortExpression="CITY" />
                <asp:BoundField DataField="STATE" HeaderText="State" SortExpression="STATE" />
                <asp:BoundField DataField="ZIP" HeaderText="Zip" SortExpression="ZIP" />
            </Columns>
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>

        <asp:SqlDataSource ID="CustInfoDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:RSardinas_6118_ConnString %>" 
            SelectCommand="GetCustomerInfo" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:SessionParameter Name="username" SessionField="UserLogIn" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    </td>

    </tr>

    <tr>
    <td>
        <asp:GridView ID="PaymentInfoGridView" runat="server" CellPadding="4" 
            ForeColor="#333333" GridLines="None" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PMTID" 
            DataSourceID="PaymentSqlDataSource" 
            onselectedindexchanged="PaymentInfoGridView_SelectedIndexChanged">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowSelectButton="True" />
                 
                <asp:BoundField DataField="PMTID" HeaderText="PMTID" ReadOnly="True" 
                     ItemStyle-CssClass="invisible" HeaderStyle-CssClass="invisible" >
                    <HeaderStyle CssClass="invisible"></HeaderStyle>
                    <ItemStyle CssClass="invisible"></ItemStyle>
                </asp:BoundField>

                <asp:BoundField DataField="CID" HeaderText="CID" 
                ItemStyle-CssClass="invisible" HeaderStyle-CssClass="invisible" >
                <HeaderStyle CssClass="invisible"></HeaderStyle>
                <ItemStyle CssClass="invisible"></ItemStyle>
                </asp:BoundField>

                <asp:BoundField HeaderText="Card Name" DataField="CNAME" SortExpression="CNAME" />

                <asp:BoundField HeaderText="Card Number" DataField="CNUM" SortExpression="CNUM" />
   
            </Columns>

            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>


        <asp:SqlDataSource ID="PaymentSqlDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:RSardinas_6118_ConnString %>" 
            SelectCommand="GetAllPaymentByCID" SelectCommandType="StoredProcedure" 
            DeleteCommand="DELETE FROM [PMT_INFO] WHERE [PMTID] = @PMTID" 
            InsertCommand="AddNewPaymentEntry" InsertCommandType="StoredProcedure" 
            UpdateCommand="UPDATE [PMT_INFO] SET [CNAME]=@CNAME, [CNUM]=@CNUM WHERE [CID]=@CID AND [PMTID]=@PMTID">
            <DeleteParameters>
                <asp:Parameter Name="paymentid" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:SessionParameter Name="customerid" SessionField="customerid" Type="Int32" />
                <asp:Parameter Name="cardnumber" Type="Int64" />
                <asp:Parameter Name="cardname" Type="String" />
            </InsertParameters>
            <SelectParameters>
                <asp:SessionParameter Name="customerid" SessionField="customerid" 
                    Type="Int32" />
            </SelectParameters>
            
            <UpdateParameters>
                <asp:SessionParameter Name="customerid" SessionField="customerid" Type="Int32" />
                <asp:Parameter Name="cardnumber" Type="Int64" />
                <asp:Parameter Name="cardname" Type="String" />
            </UpdateParameters>
            
        </asp:SqlDataSource>

        <br />
        <br />


        <asp:Button ID="AddPaymentButton" runat="server" Text="Add New Card" 
            onclick="AddPaymentButton_Click" />

        <asp:Panel ID="NoPaymentPanel" runat="server">
        
        <p>
            &nbsp;<asp:ValidationSummary ID="ValidationSummary1" runat="server" 
                ForeColor="White" />
            <p>
                Woops. It looks like you don&#39;t have any payment options on file with us. Please 
                enter your credit card information to complete this purchase.
            </p>
            <asp:Label ID="CardNameLabel" runat="server" ForeColor="White" Text="Card Name"></asp:Label>
            <br />
            <asp:TextBox ID="CNameTextBox" runat="server" Width="250px" Wrap="False"></asp:TextBox>
            <asp:RequiredFieldValidator ID="CNameRequiredFieldValidator" runat="server" 
                ControlToValidate="CNameTextBox" ErrorMessage="Please enter a name." 
                ForeColor="White">*</asp:RequiredFieldValidator>
            <br />
            <br />
            <asp:Label ID="CardNumLabel" runat="server" ForeColor="White" 
                Text="Card Number"></asp:Label>
            <br />
            <asp:TextBox ID="CNumTextBox" runat="server" CausesValidation="True" 
                Width="250px" Wrap="False"></asp:TextBox>
            <asp:RequiredFieldValidator ID="CNumRequiredFieldValidator" runat="server" 
                ControlToValidate="CNumTextBox" 
                ErrorMessage="Please enter a credit card number." ForeColor="White">*</asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="CNumberRegularExpressionValidator" 
                runat="server" ControlToValidate="CNumTextBox" ErrorMessage="It doesn't seem like this number is formatted properly.
            Please make sure that you remove all dashes and the number is
            16 digits long." ForeColor="White" ValidationExpression="[0-9]{16}">*</asp:RegularExpressionValidator>
            <br />
            <br />
            <asp:Button ID="EnterButton" runat="server" onclick="EnterButton_Click" 
                Text="Enter" />
            <asp:Button ID="ClearButton" runat="server" CausesValidation="False" 
                onclick="ClearButton_Click" Text="Cancel" UseSubmitBehavior="False" />
        </p>

        </asp:Panel>
        
    </td>

</tr>

<tr>

    <td>
        <asp:Panel ID="PurchaseCompletePanel" runat="server">
            <asp:Label ID="CompletePurchaseLabel" runat="server" ForeColor="White"></asp:Label>
        </asp:Panel>
    
    </td>

</tr>


</table>


</div>

    </asp:Content>

